package com.ruoyi.shop.emporium.brand.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.mall.common.domain.DtsAdmin;
import com.ruoyi.mall.common.domain.DtsBrand;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.shop.emporium.brand.service.IDtsBrandService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 品牌商Controller
 *
 * @author ruoyi
 * @date 2025-02-17
 */
@RestController
@RequestMapping("/emporium/brand")
public class DtsBrandController extends BaseController
{
    @Autowired
    private IDtsBrandService dtsBrandService;

    /**
     * 查询品牌商列表
     */
    @PreAuthorize("@ss.hasPermi('emporium:brand:list')")
    @GetMapping("/list")
    public TableDataInfo list(DtsBrand dtsBrand)
    {
        startPage();
        List<DtsBrand> list = dtsBrandService.selectDtsBrandList(dtsBrand);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('emporium:brand:adminlist')")
    @GetMapping("/adminlist")
    public List<DtsAdmin> brandAdmin()
    {
        return dtsBrandService.selectDtsAdminBrandList();
    }

    /**
     * 导出品牌商列表
     */
    @PreAuthorize("@ss.hasPermi('emporium:brand:export')")
    @Log(title = "品牌商", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DtsBrand dtsBrand)
    {
        List<DtsBrand> list = dtsBrandService.selectDtsBrandList(dtsBrand);
        ExcelUtil<DtsBrand> util = new ExcelUtil<DtsBrand>(DtsBrand.class);
        util.exportExcel(response, list, "品牌商数据");
    }

    /**
     * 获取品牌商详细信息
     */
    @PreAuthorize("@ss.hasPermi('emporium:brand:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dtsBrandService.selectDtsBrandById(id));
    }

    /**
     * 新增品牌商
     */
    @PreAuthorize("@ss.hasPermi('emporium:brand:add')")
    @Log(title = "品牌商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DtsBrand dtsBrand)
    {
        return toAjax(dtsBrandService.insertDtsBrand(dtsBrand));
    }

    /**
     * 修改品牌商
     */
    @PreAuthorize("@ss.hasPermi('emporium:brand:edit')")
    @Log(title = "品牌商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DtsBrand dtsBrand)
    {
        return toAjax(dtsBrandService.updateDtsBrand(dtsBrand));
    }

    /**
     * 删除品牌商
     */
    @PreAuthorize("@ss.hasPermi('emporium:brand:remove')")
    @Log(title = "品牌商", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dtsBrandService.deleteDtsBrandByIds(ids));
    }
}
